/**
 * 
 */
package view;




import javax.swing.DefaultComboBoxModel;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;


import net.miginfocom.swing.MigLayout;

/**
 * A panel for the email editor.
 * 
 * @author Farzana Alam (farzana22@gmail.com)
 * @since May 2013
 * 
 * @version $Revision: 1.0 $
 */
public class EmailEditorPanel extends JPanel {

	// Text Fields
	private JTextField from, to, subject;

	// Email Body TextPane
	private JTextPane body;
	private JScrollPane scrollPane;

	// emailTemplates combobox
	private JComboBox emailTemplatesComboBox;

	// emailTemplates model
	private DefaultComboBoxModel<String> emailTemplates;

	// Panel Buttons
	private JButton sendButton, saveButton, previewBtn;

	/**
	 * constructor
	 * 
	
	 * 
	 */
	public EmailEditorPanel() {

		super(new MigLayout("fillx"));
		initComponents();
		setupComponents();
	}

	/**
	 * Setup the components in view
	 */
	private void setupComponents() {
		
		// Email Details Panels
		this.add(new JLabel("From: "));
		this.add(from, "growx, wrap");
		this.add(new JLabel("To: "));
		this.add(to, "growx, wrap");
		this.add(new JLabel("Subject: "));
		this.add(subject, "growx, wrap");
		
		this.add(new JLabel("Apply template: "));
		this.add(emailTemplatesComboBox, "width 130, wrap");
		
		this.add(scrollPane, "span 2, width 100%, h 100:400:, wrap");

		// Buttons Panel
		JPanel buttonsPanel = new JPanel(new MigLayout("fillx, inset 0"));
		buttonsPanel.add(previewBtn, "align left");
		buttonsPanel.add(sendButton, "push, al right");
		buttonsPanel.add(saveButton, "al right");
		this.add(buttonsPanel, "width 100%, span 2");
	}

	/**
	 * sets the text labels for the compose message panel
	 * 
	
	
	 */
	private void initComponents() {

		emailTemplates = new DefaultComboBoxModel<String>();
		emailTemplatesComboBox = new JComboBox<String>(emailTemplates);
		emailTemplates.addElement("None");
		
		from = new JTextField();
		from.setEditable(false);
		to = new JTextField();
		subject = new JTextField();
		body = new JTextPane();
		scrollPane = new JScrollPane(body);
		
		saveButton = new JButton("Save", IconsManager.getImageIcon("small/mail-pencil.png"));
		sendButton = new JButton("Send", IconsManager.getImageIcon("small/mail-send.png"));
		previewBtn = new JButton("Preview", IconsManager.getImageIcon("small/eye.png"));
	}


	/**
	 * getter for _toAddress
	 * 
	
	
	 * @return JTextField _toAddress the text field for the message recipient */
	public JTextField getTo() {
		return to;
	}

	/**
	 * Getter for preview button
	 * 
	
	 * @return JButton
	 */
	public JButton getPreviewButton() {
		return previewBtn;
	}

	/**
	 * getter for _subjectField
	 * 
	
	
	 * @return JTextField _subjectField the text field for message subject */
	public JTextField getSubject() {
		return subject;
	}

	/**
	 * getter for _body
	 * 
	
	
	 * @return JTextPane _body the text pane for the message body */
	public JTextPane getBody() {
		return body;
	}

	/**
	 * getter for _fromAddress
	 * 
	
	
	 * @return JTextField _fromAddress the text field for the message
	 *         from-address field */
	public JTextField getFrom() {
		return from;
	}

	/**
	 * getter for SendButton
	 * 
	
	
	 * @return JButton sendButton the button that sends the message */
	public JButton getSendButton() {
		return sendButton;
	}

	/**
	 * getter for SaveButton
	 * 
	
	 * @return JButton saveButton */
	public JButton getSaveButton() {
		return saveButton;
	}


	/**
	 * Sets to view only mode
	 */
	public void setViewOnly() {
		remove(sendButton);
		remove(saveButton);
		body.setEditable(false);
		from.setEditable(false);
		to.setEditable(false);
		subject.setEditable(false);
	}
	
	/**
	 * Returns the email templates model
	
	 * @return DefaultComboBoxModel<String>
	 */
	public DefaultComboBoxModel<String> getEmailTemplates(){
		return emailTemplates;
	}
	
	/**
	 * Returns the templartes combobox
	
	 * @return JComboBox<String>
	 */
	public JComboBox<String> getEmailTemplatesCombobox(){
		return emailTemplatesComboBox;
	}

}
